import axios from 'axios';

axios.defaults.timeout = 60 * 1000;

axios.interceptors.request.use(config => {

    return ok.getH5AppStorage({
        key: 'token'
    }).then(res => {
        let token = res.data.data
        if (token&& config.url.indexOf('/pan/user/login')===-1) {

            if (config.method === 'get') {
                config.params.token = token
            } else {
                config.data.token = token
            }
        } 

        return config
    }).catch(err => {
        console.log("接口调用异常", err);
    });
    // return config
}, error => {
    return Promise.reject(error)
});
//HTTPresponse拦截
axios.interceptors.response.use((res) => {
    if (res.data.code !== 0&&res.config.url.indexOf('pan/token/check')=== -1) {
        ok.showToast(res.data.msg)
    }


  

    return res
}, error => {

    return Promise.reject(new Error(error));
})

export default axios;
